/********************************************AWTRIX Controller Colock***********************************************************
* Copyright (C) 2023
* Author：  Liaochao
* 
********************************************************************************************************************************/

#include <AWTRIXController.h>
// ADC_MODE(ADC_VCC);

void setup(){
  // 建立WiFiManager对象
  WiFiManager wifiManager;
  //初始化串口波特率
  Serial.begin(9600);
  //温度传感器初始化
  dht.begin();
  //初始化像素屏参数
  matrixInit();
  //按钮事件初始化
  // pinMode(A0, INPUT);
  pinMode(BUTTON1_PIN, INPUT);
  pinMode(BUTTON2_PIN, INPUT);
  // 设置按键中断（下升沿，引脚电平从高变为低时触发中断。）
  attachInterrupt(digitalPinToInterrupt(BUTTON1_PIN), touch1DownInterrupt, FALLING);
  attachInterrupt(digitalPinToInterrupt(BUTTON2_PIN), touch2DownInterrupt, FALLING);
  //显示等待配网状态
  hardwareAnimatedSearch(0, 20, 0);

  // myldr.setPhotocellPositionOnGround(false);
  //使用AP配网模式，开启热点名称为：AWTRIX 密码：123456789 连接此WIFI进行配置WIFI模块需要连接的热点信息
  wifiManager.autoConnect("AWTRIX","123456789");
  
  if (!(WiFi.status() != WL_CONNECTED)) {
    Serial.print("Local IP:");
    Serial.println(WiFi.localIP());
    //显示WIFI连接动画
    hardwareAnimatedCheck(0,  22, 2);
    //显示当前WIFI获取的IP地址
    // Show_Wifi_IP_Adresss();
  }

  //NTP获取网络时间
  NTP.setInterval (600);
  NTP.setNTPTimeout (1500);
  NTP.begin (ntpServer, timeZone, false);

  // timer.setInterval(1000L, Simple_timer_1);
  // 初始化请求一次数据，更新状态
  HeFengClient.fans(&currentWeather, BILIBILI_UID);
  HeFengClient.doUpdateCurr(&currentWeather, WEATHER_APIKEY, WEATHER_CITY);
}

void loop(){
  //NTP更新网络时间
  date_time(); 
  //以时间为随机种子             
  randomSeed(millis()); 
  //B站粉丝数更新
  if (millis() - timeSinceLastBilibiliUpdate > (1000L * Updata_Bilibili_SECS)) {
    HeFengClient.fans(&currentWeather, BILIBILI_UID);
    Serial.printf("Fans Number:%d\r\n",currentWeather.follower);
    timeSinceLastBilibiliUpdate = millis();
  }
  //天气数据更新
  if (millis() - timeSinceLastWeatherUpdate > (1000L * Updata_Weather_SECS)) { 
    HeFengClient.doUpdateCurr(&currentWeather, WEATHER_APIKEY, WEATHER_CITY);
    timeSinceLastWeatherUpdate = millis();
  }
  //显示时钟
  Work_Mode(KEY1_Count);

  // Clock_Mode();
  // //显示B站粉丝数
  // Show_BiLiBiLi_Information((currentWeather.follower)+1000);
  // Show_Brush_Animation(random(1, 5));
  // //显示天气温湿度值
  // Show_CurrentDay_Weather(meteoconIcon,currentWeather.tmp,currentWeather.hum); 
  // Show_Brush_Animation(random(1, 5));  
  // Change_Awtrix_Brightness();
  // timer.run();
}
/**********************************************************************************************************************
* 功能说明；  选择当前工作模式
* 输入参数：  按键1按下次数
* 返回值：    无
**********************************************************************************************************************/
void Work_Mode(uint8_t mode_t){
  switch (mode_t){
    case 0: //显示时间 
      RunSeconds = 0;
      RunMinute = 0;
      Timepiece_t = Pause;
      Clock_Mode();      
      break;
    case 1:    //显示日期
      DesktopCal_Mode();     
      break;
    case 2:    //显示室内温室度传感器值
      Get_Room_Temperature_Humidity(&RoomCurrentData_t);
      Show_Room_Temperature_Humidity(RoomCurrentData_t.tmp,RoomCurrentData_t.hum);   
      break;
    case 3:   //显示B站粉丝数
      Show_BiLiBiLi_Information((currentWeather.follower)+1000);   
      break;
    case 4:   //显示天气预报
      Show_CurrentDay_Weather(meteoconIcon,currentWeather.tmp,currentWeather.hum);  
      break;
    case 5:   //显示计时器功能
      Show_Timepiece_Fuction();
      break;
    case 6:   //自由模式
      Random_Mode() ;
      if ( Random_First_Flag == 0 ){
        matrix->clear();
        matrix->setTextColor(matrix->Color((random(50, 255)),(random(50, 255)),(random(50, 255))));
        matrix->setCursor(2,6);
        matrix->print("BREAK");
        matrix->show();
        delay(1000);
      } 
      break;
    case 254: //WiFI重置界面
      //像素屏显示
      matrix->clear();
      matrix->setTextColor(matrix->Color(255,0,0));
      matrix->setCursor(2,6);
      matrix->print("RESET!");
      matrix->show();
      break;
    case 255: //显示设置亮度界面
      Show_SET_Brightness(brightness);  
      break;
    default:  
      break;
  }
}
/**********************************************************************************************************************
* 功能说明；  时间模式
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
bool Clock_Mode() {
  bool res;
  LED_Color_Date data;
  Generate_LED_Color(&data);
  //显示时间
  res = Show_Time(data.R_Color,data.G_Color,data.B_Color,300);
  return res;
}
/**********************************************************************************************************************
* 功能说明；  日期模式
* 输入参数：  无
* 返回值：    是否执行完操作
**********************************************************************************************************************/
bool DesktopCal_Mode(){
  //显示年
  if ( ShoW_Year(8,8,24,200) == 0 ){
    return 0;
  }
  //刷屏动画
  if ( Show_Brush_Animation(random(1, 5)) == 0 ){
    return 0;
  }
  //显示日期
  if ( ShoW_Date(2,7,19,400) == 0 ){
    return 0;
  }
  return 1;
}
/**********************************************************************************************************************
* 功能说明；  定时刷新天气
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void Simple_timer_1(){
  static uint32_t Simple_Timer_Count = 0;
  Simple_Timer_Count++;
  if ( Simple_Timer_Count >= Updata_Weather_SECS)   //每半个小时更新一次
  {
    //向心知天气服务器服务器请求信息并对信息进行解析
    // WeatherhttpRequest(Weather_reqRes);
  }
  Serial.println("Into timer Task");
}
/**********************************************************************************************************************
* 功能说明；  显示当前室内温湿度值
* 输入参数：  int Temperature       温度值
*             int Humidity          湿度值
* 返回值：    无
**********************************************************************************************************************/
bool Show_Room_Temperature_Humidity(int Temperature,int Humidity){
  //显示温度小图标
  matrix->clear();
  matrix->drawFastVLine(2,5,2,matrix->Color(255,255,255));
  matrix->drawFastVLine(3,0,5,matrix->Color(255,255,255));
  matrix->drawFastVLine(6,5,2,matrix->Color(255,255,255));
  matrix->drawFastVLine(5,0,5,matrix->Color(255,255,255));
  matrix->drawFastVLine(4,2,3,matrix->Color(255,0,0));
  matrix->drawPixel(4,0,matrix->Color(255,255,255));
  matrix->drawFastHLine(3,7,3,matrix->Color(255,255,255));
  matrix->fillRect(3,5,3,2,matrix->Color(255,0,0));
  matrix->show();
  //显示当前温度值
  Show_Temperature(Temperature);
  if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )) {
    return 0;
  }
  //显示湿度小图标
  matrix->clear();
  matrix->drawFastVLine(0,3,3,matrix->Color(255,255,255));
  matrix->drawFastVLine(6,3,3,matrix->Color(255,255,255));
  matrix->drawPixel(3,0,matrix->Color(255,255,255));
  matrix->drawPixel(2,1,matrix->Color(255,255,255));
  matrix->drawPixel(4,1,matrix->Color(255,255,255));
  matrix->drawPixel(1,2,matrix->Color(255,255,255));
  matrix->drawPixel(5,2,matrix->Color(255,255,255));
  matrix->drawPixel(1,6,matrix->Color(255,255,255));
  matrix->drawPixel(5,6,matrix->Color(255,255,255));
  matrix->drawFastHLine(2,7,3,matrix->Color(255,255,255));
  matrix->drawFastHLine(2,6,3,matrix->Color(0,0,255));
  matrix->fillRect(1,4,5,2,matrix->Color(0,0,255));
  matrix->show();
  //显示当前湿度
  Show_Humidity(Humidity);
  if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) == 0 )) {
    return 0;
  }
  return 1;
  // Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300);
  // Show_Brush_Animation(random(1, 5));
}
/**********************************************************************************************************************
* 功能说明；  显示温度值
* 输入参数：  int Temperature       温度值
* 返回值：    无
**********************************************************************************************************************/
void Show_Temperature(int Temperature){
  LED_Color_Date data;
  Generate_LED_Color(&data);
  matrix->setTextColor(matrix->Color(data.R_Color,data.G_Color,data.B_Color));
  if ( ( Temperature > 0 ) && ( Temperature < 10 )){
      matrix->setCursor(13,6);
  }
  else{
      matrix->setCursor(10,6);
  }
  matrix->print(String(String(Temperature) + String("C")));
  if ( currentWeather.Weather_Statue == 0 ){
    matrix->setTextColor(matrix->Color(255,0,0));
    matrix->setCursor(23,6);
    matrix->print( String("!"));
  }
  matrix->show();
}
/**********************************************************************************************************************
* 功能说明；  显示当湿度值
* 输入参数：  int Humidity          湿度值
* 返回值：    无
**********************************************************************************************************************/
void Show_Humidity(int Humidity){
  LED_Color_Date data;
  Generate_LED_Color(&data);
  matrix->setTextColor(matrix->Color(data.R_Color,data.G_Color,data.B_Color));
  matrix->setCursor(10,6);
  matrix->print(String(String(Humidity) + String("%")));
  matrix->show();
}
/**********************************************************************************************************************
* 功能说明；  显示当前天气状态
* 输入参数：  int weather                     天气状态码
* 返回值：    无
**********************************************************************************************************************/
bool Show_CurrentDay_Weather(int weather,int Temperature,int Humidity){
  switch (weather){
    case 0:  //天气状态错误
      IconClient.Show_CloudyNightDay();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }   
      IconClient.Show_CloudyNightDay();
      break;
    case 1:  //晴天
      IconClient.Show_SunnyDay();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_SunnyDay();
      break;
    case 2:  //阴天
      IconClient.Show_cloudyDAY();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_cloudyDAY();
      break;
    case 3:  //雾
      IconClient.Show_Fog_Day();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_Fog_Day();
      break;
    case 4:  //沙尘
      IconClient.Show_Sandstorm();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_Sandstorm();
      break;  
    case 5:  //雪
      IconClient.Show_Snowflake();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_Snowflake();
      break;  
    case 6:  //多云
      IconClient.Show_CloudyDay();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_CloudyDay();
      break;  
    case 7: //霾
      IconClient.Show_Haze();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_Haze();
      break;  
    case 8: //雷阵雨
      IconClient.Show_Thunderstorm();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_Thunderstorm();
      break;  
    case 9: //小雨
      IconClient.Show_Rain();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_Rain();
      break; 
    case 10: //中雨
      IconClient.Show_Moderate_Rain();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_Moderate_Rain();
      break; 
    case 11: //暴雨
      IconClient.Show_Thundershower();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_Thundershower();
      break; 
    case 12: //阵雪
      IconClient.Show_Snow_Shower();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) ==0 )){
        return 0;
      }  
      IconClient.Show_Snow_Shower();
      break;
    case 13: ////中雪
      IconClient.Show_Moderate_Snow();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) == 0 )){
        return 0;
      }  
      IconClient.Show_Moderate_Snow();
      break;  
    case 14: ////雨雪
      IconClient.Show_Sleet();
      Show_Temperature(Temperature);
      if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) == 0 )){
        return 0;
      }  
      IconClient.Show_Sleet();
      break; 
    default:
      break;
  } 
  Show_Humidity(Humidity);
  if ((Show_Level_Running_Water(8,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),300) == 0 ) || (Show_Brush_Animation(random(1, 5)) == 0 )){
    return 0;
  } 
  return 1; 
}
/**********************************************************************************************************************
* 功能说明；  显示当前时间
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
bool Show_Time(uint8_t R_Color_t,uint8_t G_Color_t,uint8_t B_Color_t,uint32_t time){
  LED_Color_Date data1;

  Generate_LED_Color(&data1);
  matrix->clear();
  matrix->fillRect(0, 1, 5, 5, matrix->Color((random(50, 255)),(random(50, 255)),(random(50, 255))));
  matrix->drawCircle(2, 3, 1, matrix->Color((random(50, 255)),(random(50, 255)),(random(50, 255))));

  //显示流水效果,以及时钟点闪烁
  for(int i = 0; i < 24; i++)
  {
    if (Change_Mode_Flag == true){
      Change_Mode_Flag = false;
      return 0;
    }  
    matrix->setTextColor(matrix->Color(R_Color_t,G_Color_t,B_Color_t));
    matrix->setCursor(7,6);
    matrix->print(String(String(huor)));
    matrix->setCursor(17,6);
    matrix->print(String(String(Minute_t)));
    matrix->setTextColor(matrix->Color(data1.R_Color,data1.G_Color,data1.B_Color));
    matrix->setCursor(i,8);
    matrix->print(".");
    if ( ( i % 2 ) == 0 ){
      matrix->setTextColor(matrix->Color(R_Color_t,G_Color_t,B_Color_t));
      matrix->setCursor(15,6);
      matrix->print(String(String(":")));
    }
    else{
      matrix->setTextColor(matrix->Color(0,0,0));
      matrix->setCursor(15,6);
      matrix->print(String(String(":")));
    }
    matrix->show();
    delay(time);
  }
  return 1;
}
/**********************************************************************************************************************
* 功能说明；  显示日期
* 输入参数：  uint8_t x              起始x坐标
*             uint8_t y              起始x坐标
*             end_x                  结束X坐标
*             uint32_t Dalay_Time    每次增加一个点的延时时间
* 返回值：    无
**********************************************************************************************************************/
bool ShoW_Year(uint8_t x,uint8_t y,uint8_t end_x,uint32_t Dalay_Time){
  LED_Color_Date data2;
  bool Flag = 0;

  Generate_LED_Color(&data2);
  //显示日历小图标
  matrix->clear();
  matrix->fillRect(0,2,5,2,matrix->Color(255,255,0));
  matrix->fillRect(0,4,5,3,matrix->Color(255,255,255));
  matrix->drawPixel(1,5,matrix->Color(255,255,0));
  matrix->drawPixel(3,5,matrix->Color(255,255,0));
  matrix->drawFastVLine(1,1,2,matrix->Color(255,255,255));
  matrix->drawFastVLine(3,1,2,matrix->Color(255,255,255));
  matrix->show();
  //显示年
  matrix->setTextColor(matrix->Color(data2.R_Color,data2.G_Color,data2.B_Color)); 
  matrix->setCursor(x,6);
  matrix->print(String(String(lnyear)));
  matrix->show();
  //显示流水特效
  Flag = Show_Level_Running_Water(x,y,end_x,(random(50, 255)),(random(50, 255)),(random(50, 255)),Dalay_Time);
  return Flag;
}
/**********************************************************************************************************************
* 功能说明；  显示日期
* 输入参数：  uint8_t x              起始x坐标
*             uint8_t y              起始x坐标
*             end_x                  结束X坐标
*             uint32_t Dalay_Time    每次增加一个点的延时时间
* 返回值：    是否执行完成
**********************************************************************************************************************/
bool ShoW_Date(uint8_t x,uint8_t y,uint8_t end_x,uint32_t Dalay_Time){
  LED_Color_Date data1;

  Generate_LED_Color(&data1);
  for(int j = x; j<= end_x; j++){
    if (Change_Mode_Flag == true){
      Change_Mode_Flag = false;
      return 0;
    }  
    matrix->clear();
    matrix->setTextColor(matrix->Color(data1.R_Color,data1.G_Color,data1.B_Color));
    matrix->setCursor((j + 1),y);
    matrix->print(".");
    matrix->setCursor(x,6);
    matrix->print(String(String(lnnmonth) + String("-")) + String(lnnday));
    for (uint8_t i = 0; i < 7; i++)
    {
      matrix->drawFastHLine(2+3*i, 7, 2, matrix->Color(255,255,0));
    }
    matrix->drawFastHLine(2+3*(WeakDAY-1), 7, 2, matrix->Color(255,0,0));
    matrix->show();
    delay(Dalay_Time);
  }
  return 1;
}
/******************************************************************************************
 * 函数功能：         按键1按下去的中断
 * 输入参数：         无
 * 返回值：           无
 *****************************************************************************************/
ICACHE_RAM_ATTR void touch1DownInterrupt(){
  Serial.println("Button1 Press");
  
  Button1firstTouchTime = millis();
  attachInterrupt(digitalPinToInterrupt(BUTTON1_PIN), touch1UPInterrupt, RISING );
}
/******************************************************************************************
 * 函数功能：         按键1弹起来下去的中断
 * 输入参数：         无
 * 返回值：           无
 *****************************************************************************************/
ICACHE_RAM_ATTR void touch1UPInterrupt(){
  static uint8_t Mode_Value = 0;
  Serial.printf("Key up\r\n");
  Change_Mode_Flag = true;
  if (millis() - Button1firstTouchTime > BUTTON1_Long_Time_Threshold){   //长按
    Key1LongPressFlag++;
    if ( Key1LongPressFlag == 2 ){                    //退出设置亮度模式
      KEY1_Count = Mode_Value;                    //读取进入设置时的显示模式  
      Key1LongPressFlag = 0;
    }
    else if( Key1LongPressFlag == 1 ){                //进入设置亮度模式
      Mode_Value = KEY1_Count;                    //保存进入设置时的显示模式
      KEY1_Count = 255;
    }
    Serial.printf("button long press\r\n");
  }
  else{                                            //短按
    Serial.printf("button short press\r\n");
    if ( Key1LongPressFlag == 0 ){
      KEY1_Count++;
      if ( KEY1_Count >= AwtrixMode ){
        KEY1_Count = 0 ;
        Random_First_Flag = 0; 
      }
    }
    else if ( Key1LongPressFlag == 1 ){
      brightness +=10;
      if ( brightness > AwtrixBrightnessMax){
        brightness = 10;
      }
      matrix->setBrightness(brightness);
      Serial.printf("brightness value: %d\r\n",brightness);
    } 
  }
  attachInterrupt(digitalPinToInterrupt(BUTTON1_PIN), touch1DownInterrupt, FALLING);
}
/******************************************************************************************
 * 函数功能：         按键2按下去的中断
 * 输入参数：         无
 * 返回值：           无
 *****************************************************************************************/
ICACHE_RAM_ATTR void touch2DownInterrupt(){
  Serial.println("Button2 Press");
  
  Button2firstTouchTime = millis();
  attachInterrupt(digitalPinToInterrupt(BUTTON2_PIN), touch2UPInterrupt, RISING );
}
/******************************************************************************************
 * 函数功能：         按键2按下去的中断
 * 输入参数：         无
 * 返回值：           无
 *****************************************************************************************/
ICACHE_RAM_ATTR void touch2UPInterrupt(){
  static uint8_t KEY2_Count = 0; 
  WiFiManager wifiManager;

  Serial.println("Button2 up");
  if ( KEY1_Count == 5 ){
    if (millis() - Button2firstTouchTime > BUTTON1_Long_Time_Threshold){   //长按
      Timepiece_t = Clear;
    }
    else{
      KEY2_Count++;
      if ( (KEY2_Count % 2) == 0 ){
        Timepiece_t = Pause;
      }
      else{
        Timepiece_t = Start;
      }
    }
  }
  else{
    if (millis() - Button2firstTouchTime > BUTTON1_Long_Time_Threshold){   //长按
      Key2LongPressFlag++;
      if ( Key2LongPressFlag == 2 ){                    
        //复位WIFI
        ESP.reset(); 
      }
      else if( Key2LongPressFlag == 1 ){                
        // 重置WIFI存储的账号密码
        wifiManager.resetSettings();
        Serial.println("WiFi SSID Reset");
        KEY1_Count = 254;
        Change_Mode_Flag = true;
      }
      Serial.printf("button2 long press\r\n");
    }
    else{  
      KEY2_Count++;
      if ( (KEY2_Count % 2) == 0 ){
      }
      else{
      }
    }
  }
  attachInterrupt(digitalPinToInterrupt(BUTTON2_PIN), touch2DownInterrupt, FALLING);
}
/**********************************************************************************************************************
* 功能说明；  显示定时器功能
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void Show_Timepiece_Fuction(){
  static String RunMinute_t = "" , RunSeconds_t = "" ;
  static long LastTime = 0;
  LED_Color_Date data,data1;

  if (RunMinute >= 0 && RunMinute <= 9) {
    RunMinute_t = String("0") + String(RunMinute);
  } else {
    RunMinute_t = String(RunMinute);
  }
  if (RunSeconds >= 0 && RunSeconds <= 9) {
    RunSeconds_t = String("0") + String(RunSeconds);
  } else {
    RunSeconds_t = String(RunSeconds);
  }
  matrix->clear();
  Timepiece_ICON();
  matrix->setTextColor(matrix->Color(data.R_Color,data.G_Color,data.B_Color));
  matrix->setCursor(7,6);
  matrix->print(RunMinute_t);
  matrix->setTextColor(matrix->Color(data1.R_Color,data1.G_Color,data1.B_Color));
  matrix->setCursor(17,6);
  matrix->print(RunSeconds_t);

  if ( (RunSeconds % 2) == 0 ){
    Generate_LED_Color(&data);
    Generate_LED_Color(&data1);
    matrix->setCursor(15,6);
    matrix->setTextColor(matrix->Color(0,0,0));
    matrix->print(String(String(":")));
  }
  else{
    matrix->setCursor(15,6);
    matrix->setTextColor(matrix->Color(0,255,0));
    matrix->print(String(String(":")));
  }
  matrix->show();   

  switch (Timepiece_t){
    case Pause:
      LastTime = millis();
      break;
    case Start:
      if ( millis() - LastTime > 1000 ){
        RunSeconds++;
        LastTime = millis();   
      }
      if ( RunSeconds > 60 ){
        RunSeconds = 0;
        RunMinute++;
      }  
      break;
    case Clear:
      RunSeconds = 0;
      RunMinute = 0;
      break;
    default:
      break;
  }
}
/**********************************************************************************************************************
* 功能说明；  显示计时器小图标
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void Timepiece_ICON(){
  matrix->drawFastHLine(0,0,7,matrix->Color(255,186,0));
  matrix->drawFastHLine(0,7,7,matrix->Color(255,186,0));

  matrix->drawFastVLine(1,1,2,matrix->Color(255,186,0));
  matrix->drawFastVLine(5,1,2,matrix->Color(255,186,0));

  matrix->drawFastVLine(2,3,2,matrix->Color(255,186,0));
  matrix->drawFastVLine(4,3,2,matrix->Color(255,186,0));

  matrix->drawFastVLine(1,5,2,matrix->Color(255,186,0));
  matrix->drawFastVLine(5,5,2,matrix->Color(255,186,0));

  matrix->fillRect(2,5,3,2,matrix->Color(0,255,0));
  matrix->drawFastHLine(2,2,3,matrix->Color(0,255,0));
  matrix->drawFastVLine(3,3,2,matrix->Color(0,255,0));
}
/**********************************************************************************************************************
* 功能说明；  显示亮度
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void Show_SET_Brightness(uint8_t value){
  matrix->clear();
  Light_ICON();
  matrix->setTextColor(matrix->Color(255,0,0));
  matrix->setCursor(11,6); 
  matrix->print(String(String(value)));
  matrix->show();
}
/**********************************************************************************************************************
* 功能说明；  显示亮度小图标
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void Light_ICON(){
  matrix->drawFastHLine(2,0,4,matrix->Color(255,255,0));
  matrix->fillRect(1,1,6,3,matrix->Color(255,255,0));
  matrix->drawFastHLine(3,2,2,matrix->Color(255,255,255));
  matrix->drawPixel(2,3,matrix->Color(255,255,255));
  matrix->drawPixel(5,3,matrix->Color(255,255,255));
  matrix->fillRect(2,4,4,2,matrix->Color(255,255,0));
  matrix->fillRect(3,4,2,2,matrix->Color(255,255,255));
  matrix->drawFastHLine(2,6,4,matrix->Color(200,70,0));
  matrix->drawFastHLine(3,7,2,matrix->Color(200,70,0));
}

/**********************************************************************************************************************
* 功能说明；  产生随机颜色值
* 输入参数：  LED_Color_Date* data 输出数据
* 返回值：    无
**********************************************************************************************************************/
void Generate_LED_Color(LED_Color_Date* data){
  data->h = random(0, 360);
  data->s = random(40, 100);
  data->v = random(40, 100);
  led_HSV_To_RGB(data);
  // Serial.printf("H = %d,S = %d,V = %d\r\n",data->h,data->s,data->v);
  // Serial.printf("R = %d,G = %d,B = %d\r\n",data->R_Color,data->G_Color,data->B_Color);
  // do {
  //   data->R_Color = random(0, 255);
  //   data->G_Color = random(0, 255);
  //   data->B_Color = random(0, 255);
  //   Serial.printf("R = %d,G = %d,B = %d\r\n",data->R_Color,data->G_Color,data->B_Color);
  // } while (((data->R_Color == 0) && (data->G_Color == 0) && (data->B_Color == 0)));
}
/**********************************************************************************************************************
* 功能说明；  根据光敏电阻值来更改亮度
* 输入参数：  无
* 返回值：    计算出的亮度
**********************************************************************************************************************/
uint8_t Change_Awtrix_Brightness(){
  float Resistor = 0,Resistor_Volatge=0;
  uint8_t result = 0;
  Resistor = analogRead(A0);
  Resistor_Volatge = Resistor/1024;
  Resistor = uint8_t((map(Resistor_Volatge, 0, 1024, AwtrixBrightnessMin, AwtrixBrightnessMax)));
  Serial.println("Resistor Value: ");
  Serial.println(Resistor);
  return result;
}
/**********************************************************************************************************************
* 功能说明；  显示哔哩哔哩信息
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
bool Show_BiLiBiLi_Information(uint32_t Fans_Number){
  LED_Color_Date data1;
  int num = 0 ,count = 0 ;
  num = Fans_Number;

  Generate_LED_Color(&data1);
  if ( Fans_Number > 9999 ){
    while(num != 0) {  //计算当前粉丝数是有几位数
        num = num / 10;
        count++;
    }
    count =  -((count*4+9));
    for ( int x = 24; x >= count ; x-- ){
      if ( Change_Mode_Flag == true ){
        Change_Mode_Flag = false;
        return 0;
      }  
      matrix->clear();
      BILIBIL_ICON();  
      matrix->setCursor(9+x, 6);
      matrix->setTextColor(matrix->Color(data1.R_Color,data1.G_Color,data1.B_Color));
      matrix->print(String(String(Fans_Number)));
      matrix->show();
      delay(250);
    }
  }
  else{ //像素屏幕显示
    matrix->clear();
    BILIBIL_ICON();
    matrix->setCursor(9,6);
    matrix->setTextColor(matrix->Color(data1.R_Color,data1.G_Color,data1.B_Color));
    matrix->print(String(String(Fans_Number)));
    matrix->show();  
    if ( Show_Level_Running_Water(9,8,24,(random(50, 255)),(random(50, 255)),(random(50, 255)),400) == 0 ){
      return 0;
    }
  }
  if ( Show_Brush_Animation(random(1, 5)) == 0 ){
    return 0;
  }
  return 1; 
}
/**********************************************************************************************************************
* 功能说明；  自由显示功能
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
bool Random_Mode(){
  if ( Random_First_Flag == 0 ){
    Random_First_Flag = 1; 
    matrix->clear();
    matrix->setTextColor(matrix->Color((random(50, 255)),(random(50, 255)),(random(50, 255))));
    matrix->setCursor(0,6);
    matrix->print("Random");
    matrix->show();
    delay(1000);
  }
  if ( Clock_Mode() == 0 ){
    return 0;
  } 
  if ( Show_Brush_Animation(random(1, 5)) == 0 ){
    return 0;
  }
  if ( DesktopCal_Mode() == 0 ){
    return 0;
  }
  if ( Show_Brush_Animation(random(1, 5)) == 0 ){
    return 0;
  }
  Get_Room_Temperature_Humidity(&RoomCurrentData_t);
  if ( Show_Room_Temperature_Humidity(RoomCurrentData_t.tmp,RoomCurrentData_t.hum) == 0 ){
    return 0;
  } 
  if ( Show_BiLiBiLi_Information((currentWeather.follower)+1000) == 0 ){
    return 0;
  }
  if ( Show_CurrentDay_Weather(meteoconIcon,currentWeather.tmp,currentWeather.hum) == 0 ){
    return 0;
  }
  return 1;
}
/**********************************************************************************************************************
* 功能说明；  显示哔哩哔哩小图标
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void BILIBIL_ICON(){
    matrix->drawPixel(1,0,matrix->Color(0,0,255));
    matrix->drawPixel(6,0,matrix->Color(0,0,255));
    matrix->drawPixel(2,1,matrix->Color(0,0,255));
    matrix->drawPixel(5,1,matrix->Color(0,0,255));
    matrix->drawPixel(2,4,matrix->Color(0,0,255));
    matrix->drawPixel(5,4,matrix->Color(0,0,255));
    matrix->drawFastHLine(1,2,6,matrix->Color(0,0,255));
    matrix->drawFastHLine(1,7,6,matrix->Color(0,0,255));
    matrix->drawFastVLine(0,3,4,matrix->Color(0,0,255));
    matrix->drawFastVLine(7,3,4,matrix->Color(0,0,255));
    matrix->show();
}
/**********************************************************************************************************************
* 功能说明；  获取当前温湿度值
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void Get_Room_Temperature_Humidity(RoomCurrentData* date){
  float h = dht.readHumidity();
  float t = dht.readTemperature();
 // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    date->tmp = 24.5;
    date->hum = 65;
  }
  else{
    date->tmp = t;
    date->hum = h;
  }
  Serial.printf("Temperature:%f \r\n", date->tmp);
  Serial.printf("Humidity:%f \r\n", date->hum);
}
/* 
 * 功能：白天晴
 */
void WEATHER_ICON::Show_SunnyDay(){
  matrix->clear();
  matrix->fillRect(2,3,4,2,matrix->Color(255,255,0));
  matrix->fillRect(3,2,2,4,matrix->Color(255,255,0));
  matrix->drawPixel(2,0,matrix->Color(255,255,0));
  matrix->drawPixel(5,0,matrix->Color(255,255,0));
  matrix->drawPixel(0,2,matrix->Color(255,255,0));
  matrix->drawPixel(7,2,matrix->Color(255,255,0));
  matrix->drawPixel(0,5,matrix->Color(255,255,0));
  matrix->drawPixel(7,5,matrix->Color(255,255,0));
  matrix->drawPixel(2,7,matrix->Color(255,255,0));
  matrix->drawPixel(5,7,matrix->Color(255,255,0));
  matrix->show();
}
/* 
 * 功能：白天多云
 */
void WEATHER_ICON::Show_CloudyDay(){
  matrix->clear();
  matrix->drawPixel(2,0,matrix->Color(255,255,0));
  matrix->drawPixel(4,0,matrix->Color(255,255,0));
  matrix->drawPixel(0,1,matrix->Color(255,255,0));
  matrix->drawPixel(0,3,matrix->Color(255,255,0));
  matrix->drawFastHLine(2,2,3,matrix->Color(255,255,0));
  matrix->drawPixel(5,2,matrix->Color(255,255,255));
  matrix->fillRect(2,3,5,5,matrix->Color(255,255,255));
  matrix->drawPixel(2,3,matrix->Color(255,255,0));
  matrix->drawFastHLine(4,3,3,matrix->Color(180,180,180));
  matrix->drawFastHLine(4,4,2,matrix->Color(150,150,150));
  matrix->drawPixel(4,5,matrix->Color(150,150,150));
  matrix->drawFastVLine(1,5,2,matrix->Color(180,180,180));
  matrix->drawFastVLine(7,4,3,matrix->Color(180,180,180));
  matrix->show();
}
/* 
 * 功能：夜晚多云
 */
void WEATHER_ICON::Show_CloudyNightDay(){
  matrix->clear();
  matrix->drawFastVLine(1,2,2,matrix->Color(255,255,255));
  matrix->drawFastVLine(2,1,4,matrix->Color(255,255,255));
  matrix->drawFastHLine(2,4,2,matrix->Color(255,255,255));
  matrix->drawFastHLine(3,5,4,matrix->Color(255,255,255));
  matrix->drawFastHLine(3,6,2,matrix->Color(128,128,128));
  matrix->drawPixel(0,0,matrix->Color(255,255,255));
  matrix->drawPixel(3,0,matrix->Color(255,255,255));
  matrix->drawPixel(6,1,matrix->Color(255,255,0));
  matrix->drawPixel(1,4,matrix->Color(128,128,128));
  matrix->drawPixel(7,4,matrix->Color(255,255,255));
  matrix->drawPixel(2,5,matrix->Color(128,128,128));
  matrix->drawPixel(1,7,matrix->Color(255,255,255));
  matrix->drawPixel(7,7,matrix->Color(255,255,255));
  matrix->show();
}
/* 
 * 功能：阴
 */
void WEATHER_ICON::Show_cloudyDAY(){
  matrix->clear();
  matrix->drawFastVLine(1,2,2,matrix->Color(100,100,100));
  matrix->drawFastVLine(5,1,2,matrix->Color(100,100,100));
  matrix->drawPixel(4,2,matrix->Color(100,100,100));
  matrix->drawPixel(7,2,matrix->Color(100,100,100));
  matrix->drawFastHLine(5,2,2,matrix->Color(200,200,200));
  matrix->drawFastHLine(0,3,8,matrix->Color(190,190,190));
  matrix->drawPixel(0,3,matrix->Color(100,100,100));
  matrix->drawPixel(3,3,matrix->Color(100,100,100));
  matrix->drawFastHLine(0,4,7,matrix->Color(180,180,180));
  matrix->drawFastHLine(0,5,7,matrix->Color(150,150,150));
  matrix->drawPixel(0,5,matrix->Color(100,100,100));
  matrix->drawPixel(7,5,matrix->Color(100,100,100));
  matrix->drawFastHLine(1,6,6,matrix->Color(110,110,110));
  matrix->show();
}
/* 
 * 功能：沙尘
 */
void WEATHER_ICON::Show_Sandstorm(){
  matrix->clear();
  matrix->drawFastHLine(2,0,3,matrix->Color(128,64,0));
  matrix->drawFastHLine(2,2,3,matrix->Color(128,64,0));
  matrix->drawFastHLine(2,5,3,matrix->Color(128,64,0));
  matrix->drawFastHLine(2,7,3,matrix->Color(128,64,0));
  matrix->drawPixel(1,1,matrix->Color(128,64,0));
  matrix->drawPixel(5,1,matrix->Color(128,64,0));
  matrix->drawPixel(0,3,matrix->Color(128,64,0));
  matrix->drawPixel(6,3,matrix->Color(128,64,0));
  matrix->drawPixel(1,4,matrix->Color(128,64,0));
  matrix->drawPixel(5,4,matrix->Color(128,64,0));
  matrix->drawPixel(0,5,matrix->Color(128,64,0));
  matrix->drawPixel(6,5,matrix->Color(128,64,0));
  matrix->drawPixel(1,6,matrix->Color(128,64,0));
  matrix->drawPixel(5,6,matrix->Color(128,64,0));
  matrix->show();
}
/* 
 * 功能：霾  - 小火龙图标
 */
void WEATHER_ICON::Show_Haze(){
  matrix->clear();
  matrix->drawFastHLine(1,1,4,matrix->Color(255,0,0));
  matrix->drawFastHLine(0,3,5,matrix->Color(255,0,0));
  matrix->drawPixel(0,2,matrix->Color(255,0,0));
  matrix->drawPixel(2,2,matrix->Color(255,0,0));
  matrix->drawPixel(4,2,matrix->Color(255,0,0));
  matrix->drawFastVLine(4,4,2,matrix->Color(255,0,0));
  matrix->drawFastHLine(2,4,2,matrix->Color(220,60,0));
  matrix->fillRect(2,5,2,2,matrix->Color(255,255,0));
  matrix->drawPixel(1,5,matrix->Color(255,0,0));
  matrix->drawPixel(2,7,matrix->Color(255,0,0));
  matrix->drawPixel(4,7,matrix->Color(255,0,0));
  matrix->drawPixel(4,6,matrix->Color(220,60,0));
  matrix->drawPixel(5,6,matrix->Color(255,0,0));
  matrix->drawPixel(6,3,matrix->Color(220,60,0));
  matrix->drawPixel(6,4,matrix->Color(255,165,0));
  matrix->drawPixel(6,5,matrix->Color(255,0,0));
  matrix->show();
}
/* 
 * 功能：雾
 */
void WEATHER_ICON::Show_Fog_Day(){
  matrix->clear();
  matrix->drawFastHLine(2,3,3,matrix->Color(160,160,160));
  matrix->drawFastHLine(2,6,3,matrix->Color(160,160,160));
  matrix->drawPixel(2,0,matrix->Color(160,160,160));
  matrix->drawPixel(4,0,matrix->Color(160,160,160));
  matrix->drawPixel(3,1,matrix->Color(160,160,160));
  matrix->drawPixel(1,2,matrix->Color(160,160,160));
  matrix->drawPixel(5,2,matrix->Color(160,160,160));
  matrix->drawPixel(0,4,matrix->Color(160,160,160));
  matrix->drawPixel(1,5,matrix->Color(160,160,160));
  matrix->drawPixel(6,4,matrix->Color(160,160,160));
  matrix->drawPixel(5,5,matrix->Color(160,160,160));
  matrix->show();
}
/* 
 * 功能：雨
 */
void WEATHER_ICON::Show_Rain(){
  matrix->clear();
  matrix->fillRect(1,1,2,4,matrix->Color(255,255,255));
  matrix->fillRect(2,3,5,2,matrix->Color(255,255,255));
  matrix->fillRect(4,1,4,3,matrix->Color(255,255,255));
  matrix->drawPixel(5,0,matrix->Color(150,150,150));
  matrix->drawPixel(4,1,matrix->Color(150,150,150));
  matrix->drawPixel(7,1,matrix->Color(150,150,150));
  matrix->drawPixel(0,2,matrix->Color(150,150,150));
  matrix->drawPixel(1,4,matrix->Color(150,150,150));
  matrix->drawPixel(0,3,matrix->Color(255,255,255));
  matrix->drawPixel(6,0,matrix->Color(255,255,255));
  matrix->drawPixel(1,5,matrix->Color(0,255,255));
  matrix->drawPixel(0,6,matrix->Color(0,255,255));
  matrix->drawPixel(4,5,matrix->Color(0,255,255));
  matrix->drawPixel(3,6,matrix->Color(0,255,255));
  matrix->drawPixel(2,7,matrix->Color(0,255,255));
  matrix->drawPixel(7,5,matrix->Color(0,255,255));
  matrix->drawPixel(6,6,matrix->Color(0,255,255));
  matrix->drawPixel(5,7,matrix->Color(0,255,255));
  matrix->show();
}
/* 
 * 功能：中雨
 */
void WEATHER_ICON::Show_Moderate_Rain(){
  matrix->clear();
  matrix->fillRect(1,1,2,4,matrix->Color(255,255,255));
  matrix->fillRect(2,3,5,2,matrix->Color(255,255,255));
  matrix->fillRect(4,1,4,3,matrix->Color(255,255,255));
  matrix->drawPixel(5,0,matrix->Color(150,150,150));
  matrix->drawPixel(4,1,matrix->Color(150,150,150));
  matrix->drawPixel(7,1,matrix->Color(150,150,150));
  matrix->drawPixel(0,2,matrix->Color(150,150,150));
  matrix->drawPixel(1,4,matrix->Color(150,150,150));
  matrix->drawPixel(0,3,matrix->Color(255,255,255));
  matrix->drawPixel(6,0,matrix->Color(255,255,255));
  matrix->drawPixel(1,5,matrix->Color(255,255,0));
  matrix->drawPixel(0,6,matrix->Color(255,255,0));
  matrix->drawPixel(4,5,matrix->Color(255,255,0));
  matrix->drawPixel(3,6,matrix->Color(255,255,0));
  matrix->drawPixel(2,7,matrix->Color(255,255,0));
  matrix->drawPixel(7,5,matrix->Color(255,255,0));
  matrix->drawPixel(6,6,matrix->Color(255,255,0));
  matrix->drawPixel(5,7,matrix->Color(255,255,0));
  matrix->show();
}
/* 
 * 功能：暴雨
 */
void WEATHER_ICON::Show_Thundershower(){
  matrix->clear();
  matrix->fillRect(1,1,2,4,matrix->Color(255,255,255));
  matrix->fillRect(2,3,5,2,matrix->Color(255,255,255));
  matrix->fillRect(4,1,4,3,matrix->Color(255,255,255));
  matrix->drawPixel(5,0,matrix->Color(150,150,150));
  matrix->drawPixel(4,1,matrix->Color(150,150,150));
  matrix->drawPixel(7,1,matrix->Color(150,150,150));
  matrix->drawPixel(0,2,matrix->Color(150,150,150));
  matrix->drawPixel(1,4,matrix->Color(150,150,150));
  matrix->drawPixel(0,3,matrix->Color(255,255,255));
  matrix->drawPixel(6,0,matrix->Color(255,255,255));

  matrix->drawPixel(1,5,matrix->Color(255,0,0));
  matrix->drawPixel(0,6,matrix->Color(255,0,0));
  matrix->drawPixel(4,5,matrix->Color(255,0,0));
  matrix->drawPixel(3,6,matrix->Color(255,0,0));
  matrix->drawPixel(2,7,matrix->Color(255,0,0));
  matrix->drawPixel(7,5,matrix->Color(255,0,0));
  matrix->drawPixel(6,6,matrix->Color(255,0,0));
  matrix->drawPixel(5,7,matrix->Color(255,0,0));
  matrix->show();
}
/* 
 * 功能：雷雨
 */
void WEATHER_ICON::Show_Thunderstorm(){
  matrix->clear();
  matrix->fillRect(2,3,2,2,matrix->Color(255,255,255));
  matrix->fillRect(4,2,2,3,matrix->Color(255,255,255));
  matrix->drawFastVLine(1,3,2,matrix->Color(100,100,100));
  matrix->drawFastVLine(6,2,4,matrix->Color(100,100,100));
  matrix->drawFastHLine(0,5,4,matrix->Color(100,100,100));
  matrix->drawFastHLine(2,2,2,matrix->Color(100,100,100));
  matrix->drawFastHLine(4,1,2,matrix->Color(100,100,100));
  matrix->drawFastHLine(5,5,3,matrix->Color(100,100,100));
  matrix->drawPixel(4,3,matrix->Color(255,255,0));
  matrix->drawPixel(3,4,matrix->Color(255,255,0));
  matrix->drawPixel(4,5,matrix->Color(255,255,0));
  matrix->drawPixel(3,6,matrix->Color(255,255,0));
  matrix->drawPixel(2,7,matrix->Color(255,255,0));
  matrix->drawPixel(1,6,matrix->Color(0,0,255));
  matrix->drawPixel(0,7,matrix->Color(0,0,255));
  matrix->drawPixel(6,6,matrix->Color(0,0,255));
  matrix->drawPixel(5,7,matrix->Color(0,0,255));
  matrix->show();
}
/* 
 * 功能：雪晴（小雪人）雨雪天气
 */
void WEATHER_ICON::Show_Sleet(){
  matrix->clear();
  matrix->fillRect(2,1,4,3,matrix->Color(255,255,255));
  matrix->fillRect(1,4,6,4,matrix->Color(255,255,255));
  matrix->drawFastVLine(0,5,2,matrix->Color(205,133,63));
  matrix->drawFastVLine(7,5,2,matrix->Color(205,133,63));
  matrix->drawPixel(1,6,matrix->Color(205,133,63));
  matrix->drawPixel(6,6,matrix->Color(205,133,63));
  matrix->drawFastHLine(3,0,2,matrix->Color(255,0,0));
  matrix->drawFastHLine(3,3,2,matrix->Color(100,100,100));
  matrix->drawPixel(2,2,matrix->Color(0,0,255));
  matrix->drawPixel(5,2,matrix->Color(0,0,255));
  matrix->show();
}
/* 
 * 功能：小雪
 */
void WEATHER_ICON::Show_Snowflake(){
  matrix->clear();
  matrix->drawFastVLine(3,0,4,matrix->Color(230,255,255));
  matrix->drawFastHLine(2,1,3,matrix->Color(230,255,255));
  matrix->drawFastVLine(1,3,3,matrix->Color(230,255,255));
  matrix->drawFastHLine(0,4,4,matrix->Color(230,255,255));
  matrix->drawFastVLine(4,4,4,matrix->Color(230,255,255));
  matrix->drawFastHLine(3,6,3,matrix->Color(230,255,255));
  matrix->drawFastVLine(6,2,3,matrix->Color(230,255,255));
  matrix->drawFastHLine(4,3,4,matrix->Color(230,255,255));
  matrix->show();
}
/* 
 * 功能：中雪
 */
void WEATHER_ICON::Show_Moderate_Snow(){
  matrix->clear();
  matrix->drawFastVLine(3,0,4,matrix->Color(0,128,128));
  matrix->drawFastHLine(2,1,3,matrix->Color(0,128,128));
  matrix->drawFastVLine(1,3,3,matrix->Color(0,128,128));
  matrix->drawFastHLine(0,4,4,matrix->Color(0,128,128));
  matrix->drawFastVLine(4,4,4,matrix->Color(0,128,128));
  matrix->drawFastHLine(3,6,3,matrix->Color(0,128,128));
  matrix->drawFastVLine(6,2,3,matrix->Color(0,128,128));
  matrix->drawFastHLine(4,3,4,matrix->Color(0,128,128));
  matrix->show();
}
/* 
 * 功能：阵雪
 */
void WEATHER_ICON::Show_Snow_Shower(){
  matrix->clear();
  matrix->drawFastVLine(3,0,4,matrix->Color(0,0,255));
  matrix->drawFastHLine(2,1,3,matrix->Color(0,0,255));
  matrix->drawFastVLine(1,3,3,matrix->Color(0,0,255));
  matrix->drawFastHLine(0,4,4,matrix->Color(0,0,255));
  matrix->drawFastVLine(4,4,4,matrix->Color(0,0,255));
  matrix->drawFastHLine(3,6,3,matrix->Color(0,0,255));
  matrix->drawFastVLine(6,2,3,matrix->Color(0,0,255));
  matrix->drawFastHLine(4,3,4,matrix->Color(0,0,255));
  matrix->show();
}
/* 
 * 功能：未知天气
 */
void WEATHER_ICON::Show_Error_Weather(){
  matrix->clear();
  matrix->drawFastHLine(4,5,3,matrix->Color(255,255,255));
  matrix->drawPixel(1,1,matrix->Color(255,255,255));
  matrix->drawPixel(2,2,matrix->Color(255,255,255));
  matrix->drawPixel(3,3,matrix->Color(255,255,255));
  matrix->drawPixel(2,4,matrix->Color(255,255,255));
  matrix->drawPixel(1,5,matrix->Color(255,255,255));
  matrix->setTextColor(matrix->Color(255,0,0));
  matrix->setCursor(10,6);
  matrix->print("ERR!");
  matrix->show();
}
/* 
 * 功能：风
 */
void WEATHER_ICON::Show_Wind_Day(){
  matrix->clear();
  matrix->fillRect(2,2,3,2,matrix->Color(255,255,255));
  matrix->drawFastHLine(0,0,2,matrix->Color(255,255,255));
  matrix->drawFastHLine(1,1,2,matrix->Color(255,255,255));
  matrix->drawFastHLine(4,1,2,matrix->Color(255,255,255));
  matrix->drawFastHLine(5,0,2,matrix->Color(255,255,255));
  matrix->drawFastHLine(4,4,3,matrix->Color(255,255,255));
  matrix->drawPixel(6,5,matrix->Color(255,255,255));
  matrix->drawFastVLine(1,3,2,matrix->Color(255,255,255));
  matrix->drawFastVLine(0,4,2,matrix->Color(255,255,255));
  matrix->drawFastVLine(3,4,4,matrix->Color(130,130,130));
  matrix->show();
}
/**********************************************************************************************************************
* 功能说明；  像素屏参数初始化
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void matrixInit(){
	matrix = new FastLED_NeoMatrix(leds, MATRIX_Weight, MATRIX_Hight, NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE);
	FastLED.addLeds<NEOPIXEL, D2>(leds, LED_Number).setCorrection(TypicalLEDStrip);
	matrix->begin();
	matrix->setTextWrap(false);
	matrix->setBrightness(AwtrixBrightnessMin);
	matrix->setFont(&TomThumb);
}
/**********************************************************************************************************************
* 功能说明；  获取当前网络时间
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void date_time() {
  if (NTP.getTimeHour24() >= 0 && NTP.getTimeHour24() <= 9) {
    huor = String("0") + String(NTP.getTimeHour24());
  } else {
    huor = NTP.getTimeHour24();
  }
  if (NTP.getTimeMinute() >= 0 && NTP.getTimeMinute() <= 9) {
    Minute_t = String("0") + String(NTP.getTimeMinute());
  } else {
    Minute_t = NTP.getTimeMinute();
  }
  if (NTP.getTimeSecond() >= 0 && NTP.getTimeSecond() <= 9) {
    seconds = String("0") + String(NTP.getTimeSecond());
  } else {
    seconds = NTP.getTimeSecond();
  }
  if (NTP.getDateMonth() >= 0 && NTP.getDateMonth() <= 9) {
    lnnmonth = String("0") + String(NTP.getDateMonth());
  } else {
    lnnmonth = NTP.getDateMonth();
  }
  if (NTP.getDateDay() >= 0 && NTP.getDateDay() <= 9) {
    lnnday = String("0") + String(NTP.getDateDay());
  } else {
    lnnday = NTP.getDateDay();     //获取当前是几号
  }
  WeakDAY = NTP.getDateWeekday();  //获取当前是周几
  lnyear =  String(NTP.getDateYear());
}
/**********************************************************************************************************************
* 功能说明；  HSV转RGB值
* 输入参数：  LED_Color_Date* data      数据
*             Wiki: https://en.wikipedia.org/wiki/HSL_and_HSV
* 返回值：    无
**********************************************************************************************************************/
static void led_HSV_To_RGB(LED_Color_Date* data){
    data->h %= 360; /**< h -> [0,360] */
    uint32_t rgb_max = data->v * 2.55f;
    uint32_t rgb_min = rgb_max * (100 - data->s) / 100.0f;

    uint32_t i = data->h / 60;
    uint32_t diff = data->h % 60;

    /**< RGB adjustment amount by hue */
    uint32_t rgb_adj = (rgb_max - rgb_min) * diff / 60;
    switch (i) {
        case 0:
            data->R_Color = rgb_max;
            data->G_Color = rgb_min + rgb_adj;
            data->B_Color = rgb_min;
            break;
        case 1:
            data->R_Color = rgb_max - rgb_adj;
            data->G_Color = rgb_max;
            data->B_Color = rgb_min;
            break;
        case 2:
            data->R_Color = rgb_min;
            data->G_Color = rgb_max;
            data->B_Color = rgb_min + rgb_adj;
            break;
        case 3:
            data->R_Color = rgb_min;
            data->G_Color = rgb_max - rgb_adj;
            data->B_Color = rgb_max;
            break;
        case 4:
            data->R_Color = rgb_min + rgb_adj;
            data->G_Color = rgb_min;
            data->B_Color = rgb_max;
            break;
        default:
            data->R_Color = rgb_max;
            data->G_Color = rgb_min;
            data->B_Color = rgb_max - rgb_adj;
            break;
    }
}
/**********************************************************************************************************************
* 功能说明；  水平显示流水效果
* 输入参数：  uint8_t x              起始x坐标
*             uint8_t y             起始x坐标
*             uint8_t number        结束X坐标
*             uint8_t R_Color_t     灯珠的R颜色参数
*             uint8_t G_Color_t     灯珠的G颜色参数
*             uint8_t B_Color_t     灯珠的B颜色参数
*             uint16_t Add_Time     灯珠的递增时间
* 返回值：    是否执行完成
**********************************************************************************************************************/
bool Show_Level_Running_Water(uint8_t x,uint8_t y,uint8_t End_x,uint8_t R_Color_t,uint8_t G_Color_t,uint8_t B_Color_t,uint16_t Add_Time){
  uint8_t temp_Number = x;

  for(int i = x; i < End_x; i++){
    if (Change_Mode_Flag == true){
      Change_Mode_Flag = false;
      return 0;
    }  
    matrix->setTextColor(matrix->Color(R_Color_t,G_Color_t,B_Color_t));
    matrix->setCursor(temp_Number ,y);
    matrix->print(".");
    matrix->show();
    delay(Add_Time);
    temp_Number++;
  }
  return 1;
}
/**********************************************************************************************************************
* 功能说明；  页面切换刷屏效果
* 输入参数：  uint8_t item              显示项目
* 返回值：    是否执行完成
**********************************************************************************************************************/
bool Show_Brush_Animation(uint8_t kind){
  if (Change_Mode_Flag == true){
      Change_Mode_Flag = false;
      return 0;
  }  
  switch (kind) {
   case 1:
    for(int j = -3; j<= 33; j++)
    {
      matrix->clear();
      matrix->drawFastVLine(j + 1, 0, 8, matrix->Color(0,200,160));
      matrix->show();
      delay(15);
    }
    break;
   case 2:
    for(int j = 32; j>-3; j--)
    {
      matrix->clear();
      matrix->drawFastVLine(j + 1, 0, 8, matrix->Color(0,200,160));
      matrix->show();
      delay(15);
    }
    break;
   case 3:
    for(int j = -3; j<=10; j++)
    {
      matrix->clear();
      matrix->drawFastHLine(0, j + 1, 32, matrix->Color(100,255,100));
      matrix->show();
      delay(30);
    }
    break;
   case 4:
    for(int j = 10; j>-3; j--)
    {
      matrix->clear();
      matrix->drawFastHLine(0, j + 1, 32, matrix->Color(100,255,100));
      matrix->show();
      delay(30);
    }
    break;
   default:
    break;
  }
  return 1;
}
/**********************************************************************************************************************
* 功能说明；  显示WIFI连接网络动画
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void hardwareAnimatedSearch(int typ, int x, int y)
{
	for (int i = 0; i < 4; i++)
	{
		matrix->clear();
		matrix->setTextColor(0xFF22);
		if (typ == 0)
		{
			matrix->setCursor(2, 6);
			matrix->print("WiFi");
		}
		switch (i)
		{
		case 3:
			matrix->drawPixel(x, y, 0x22ff);
			matrix->drawPixel(x + 1, y + 1, 0x22ff);
			matrix->drawPixel(x + 2, y + 2, 0x22ff);
			matrix->drawPixel(x + 3, y + 3, 0x22ff);
			matrix->drawPixel(x + 2, y + 4, 0x22ff);
			matrix->drawPixel(x + 1, y + 5, 0x22ff);
			matrix->drawPixel(x, y + 6, 0x22ff);
		case 2:
			matrix->drawPixel(x - 1, y + 2, 0x22ff);
			matrix->drawPixel(x, y + 3, 0x22ff);
			matrix->drawPixel(x - 1, y + 4, 0x22ff);
		case 1:
			matrix->drawPixel(x - 3, y + 3, 0x22ff);
		case 0:
			break;
		}
		matrix->show();
		delay(300);
	}
}
/**********************************************************************************************************************
* 功能说明；  显示WIFI当前IP
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void hardwareAnimatedCheck(int typ, int x, int y){
	int wifiCheckTime = millis();
	int wifiCheckPoints = 0;
	while (millis() - wifiCheckTime < 2000){
		while (wifiCheckPoints < 7){
			matrix->clear();
			switch (typ){
			case 0:
				matrix->setCursor(2, 6);
				matrix->print("WiFi");
				break;
			case 1:
				matrix->setCursor(5, 6);
				matrix->print("Host");
				break;
			}

			switch (wifiCheckPoints){
			case 6:
				matrix->drawPixel(x, y, 0x07E0);
			case 5:
				matrix->drawPixel(x - 1, y + 1, 0x07E0);
			case 4:
				matrix->drawPixel(x - 2, y + 2, 0x07E0);
			case 3:
				matrix->drawPixel(x - 3, y + 3, 0x07E0);
			case 2:
				matrix->drawPixel(x - 4, y + 4, 0x07E0);
			case 1:
				matrix->drawPixel(x - 5, y + 3, 0x07E0);
			case 0:
				matrix->drawPixel(x - 6, y + 2, 0x07E0);
				break;
			}
			wifiCheckPoints++;
			matrix->show();
			delay(100);
		}
	}
}
/**********************************************************************************************************************
* 功能说明；  显示WIFI当前获取的IP地址
* 输入参数：  无
* 返回值：    无
**********************************************************************************************************************/
void Show_Wifi_IP_Adresss(){
  for (int x = 32; x >= -100; x--)
	{
		matrix->clear();
		matrix->setCursor(x, 6);
		matrix->print("Local IP:" + WiFi.localIP().toString());
		matrix->setTextColor(matrix->Color(0, 255, 50));
		matrix->show();
		delay(40);
	}
}